import { resolve } from 'path'
import modifyAppId from './modify-appId'
import modifyLiveId from './modify-live-id'
import modifyMapKey from './modify-map-key'
import { loadEnv } from 'vite'

export default function modifyAssemble(mode: string) {
    return () => {
        const baseUrl = process.cwd()
        const platform = process.env.UNI_PLATFORM
        const manifestPath = resolve('./src/manifest.json')
        const pagesPath = resolve('./src/pages.json')
        const environmentObj = loadEnv(mode, baseUrl) as unknown as ImportMetaEnv

        if (platform === 'mp-weixin') {
            // 修改 appid
            modifyAppId(environmentObj)
            // 修改 wx 直播 id
            modifyLiveId(pagesPath, environmentObj)
        }

        // 修改 mapkey
        modifyMapKey(environmentObj)
    }
}
